var db = require("../models");

//新增消息
exports.CreateMsg = function(data, callback){
	var newMessage = new db.Message(data);
	newMessage.content = data.content;
	newMessage.creator._id = data.user._id;
	newMessage.creator.name = data.user.name;
	newMessage.creator.headUrl = data.user.headUrl;
	newMessage._roomId = data._roomId;
	newMessage.save(callback);
}
//初始化获取房间全部消息
exports.getAllMessage = function(callback){
	db.Message.find({}, null, {
		sort: {
			"createAt": -1
		},
		limit: 20
	}, function(err, data){
		callback(null, data.reverse())
	})
}
